package com.pkk.penguin.frame.know.java.interview.year2021.atguigu_20210226.thread;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import org.junit.Test;

/**
 * 线程池测试
 *
 * @author peikunkun
 * @version V1.0
 * @date 2021-03-19 10:16
 **/
public class ThreadPoolSimple1 {


  @Test
  public void Administrator_14_20210319101652_() {
    System.out.println("欢迎使用单元测试方法【Administrator_14()_20210319101652】");
    System.out.println("此方法测试描述：【】");

    //，我强烈不推荐使用它，因为Executors中的newFixedThreadPool和newSingleThreadExecutor方法创建的线程池中，阻塞队列LinkedBlockingQueue的长度是Integer.MAX_VALUE，可能会堆积大量的任务，从而导致 OOM；

    Executors.newFixedThreadPool(1);
    Executors.newSingleThreadExecutor();
    Executors.newCachedThreadPool(new ThreadFactory() {

      /**
       * Constructs a new {@code Thread}.  Implementations may also initialize
       * priority, name, daemon status, {@code ThreadGroup}, etc.
       *
       * @param r a runnable to be executed by new thread instance
       * @return constructed thread, or {@code null} if the request to
       * create a thread is rejected
       */
      @Override
      public Thread newThread(Runnable r) {
        return new Thread("test-" + r.hashCode());
      }
    });

    Executors.newScheduledThreadPool(1);
  }
}
